% /*******************************************************************************
%  * Constant Correction Method : constant calculation
%  * *****************************************************************************
%  * Compute the Correction Constant, as an estimation of truncated part. For more
%  * detail, see @text(Stine04 p73). In summary,
%  * CC = -round(2^(r+k)*E_total)/2^(r+k)
%  * E_total = E_reduction + E_rounding
%  * E_reduction = E{LSP_minor) (mean of truncated part-least sig. part)
%  * E_rounding = E{rounded product} (k  extra bits)
%  * (Assumption: (1/2 1/2) for each bits)
%  * 
%  * @param m     Multiplicand Width
%  * @param n     Multiplier Width
%  * @param r     Product Width
%  * @param k     Extra bits to keep
%  * @param p	  Probability
%  * @return      Correction Constant
%  */
function [err_rnd, err_red, err_total] = ccm_const_prob(m,n,r,k,p)
err_red = double(0);
%Compute E_reduction, it's mean of truncated part(in Partial Products)
for q = r+k+1:m+n
    err_red = err_red + (m+n+1-q) * 2^(-q);
end
%Compute E_rounding, it's mean of rounded part of Product
err_rnd = 2^(-r) * (1-2^(-k));
err_rnd = p * err_rnd; 
err_red = (p^2) * err_red;
err_total = err_red + err_rnd;
end
